<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../gsap.min.js"></script>
  <script src="../gsap-public/minified/ScrollTrigger.min.js"></script>
  <script src="../gsap-public/minified/ScrollToPlugin.min.js"></script>
  <style>
    .box {
      width: 200px;
      height: 200px;
      margin: 300px 0;
    }
    .box1 {
      background-color: red;
    }
    .box2 {
      background-color: green;
    }
    .box3 {
      background-color: blue;
    }
    .box4 {
      background-color: yellow;
    }
    .box5 {
      background-color: orange;
    }
    .ghost {
      background-color: gray;
    }
  </style>
</head>
<body>
  <div class="box box1"></div>
  <div class="box box2"></div>
  <div class="box box3"></div>
  <div class="box box4"></div>
  <div class="box box5"></div>
  <script>
    gsap.registerPlugin(ScrollTrigger);
    gsap.to('.box3', {
      // scrollTrigger: '.box5',
      scrollTrigger: {
        trigger: '.box3',
        start: 'top center', // top 是 box3 的top， center 是屏幕的中间。
        scrub: 3,
        pin: '.ghost',
        // end: 'bottom 80%',
        // endTrigger: '.box3',
        // end: () => '+= ' + document.querySelector('.box3').offsetWidth,
        markers: true,
        toggleActions: 'restart pause reverse none'
      },
      x: 400,
      rotation: 360,
      duration: 3
    });
  </script>
</body>
</html>